package cn.iocoder.yudao.module.mini.dal.mysql.user;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mini.controller.admin.user.vo.UserExportReqVO;
import cn.iocoder.yudao.module.mini.controller.admin.user.vo.UserPageReqVO;
import cn.iocoder.yudao.module.mini.dal.dataobject.user.UserDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 小程序用户 Mapper
 *
 * @author dzy
 */
@Mapper
public interface MiniUserMapper extends BaseMapperX<UserDO> {

    default PageResult<UserDO> selectPage(UserPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserDO>()
                .likeIfPresent(UserDO::getNickname, reqVO.getNickname())
                .eqIfPresent(UserDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UserDO::getStatus, reqVO.getStatus())
                .eqIfPresent(UserDO::getMobile, reqVO.getMobile())
                .eqIfPresent(UserDO::getIdCard, reqVO.getIdCard())
                .eqIfPresent(UserDO::getSex, reqVO.getSex())
                .eqIfPresent(UserDO::getRole, reqVO.getRole())
                .eqIfPresent(UserDO::getPassword, reqVO.getPassword())
                .eqIfPresent(UserDO::getRegisterIp, reqVO.getRegisterIp())
                .eqIfPresent(UserDO::getLoginIp, reqVO.getLoginIp())
                .betweenIfPresent(UserDO::getLoginDate, reqVO.getLoginDate())
                .betweenIfPresent(UserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserDO::getId));
    }

    default List<UserDO> selectList(UserExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserDO>()
                .likeIfPresent(UserDO::getNickname, reqVO.getNickname())
                .eqIfPresent(UserDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UserDO::getStatus, reqVO.getStatus())
                .eqIfPresent(UserDO::getMobile, reqVO.getMobile())
                .eqIfPresent(UserDO::getIdCard, reqVO.getIdCard())
                .eqIfPresent(UserDO::getSex, reqVO.getSex())
                .eqIfPresent(UserDO::getRole, reqVO.getRole())
                .eqIfPresent(UserDO::getPassword, reqVO.getPassword())
                .eqIfPresent(UserDO::getRegisterIp, reqVO.getRegisterIp())
                .eqIfPresent(UserDO::getLoginIp, reqVO.getLoginIp())
                .betweenIfPresent(UserDO::getLoginDate, reqVO.getLoginDate())
                .betweenIfPresent(UserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserDO::getId));
    }

}
